package com.game.actions;

import com.game.controllers.ShootController;
import com.game.objects.Environment;
import com.game.objects.Player;
import com.game.system.Utils;
import com.jme.bounding.BoundingBox;
import com.jme.input.action.InputAction;
import com.jme.input.action.InputActionEvent;
import com.jme.light.LightNode;
import com.jme.light.PointLight;
import com.jme.light.SimpleLightNode;
import com.jme.light.SpotLight;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.SharedMesh;
import com.jme.scene.TriMesh;
import com.jme.scene.state.LightState;
import com.jme.scene.state.RenderState;
import com.jme.system.DisplaySystem;

public class ShootAction extends InputAction{
	private Player player;
	private TriMesh model;
	private int numBullets;
	private Environment ev;
	public ShootAction(Player player, Environment ev){
		this.ev=ev;
		this.player = player;
		model = (TriMesh)Utils.loadModel("shot");
	}
	public void performAction(InputActionEvent evt) {
		SharedMesh[] bullet = new SharedMesh[2];
		Vector3f direction = player.getPlayer().getLocalRotation().getRotationColumn(2);
		for(int i=0; i<bullet.length; i++){
			bullet[i] = new SharedMesh("shot"+numBullets++, model);
			bullet[i].setModelBound(new BoundingBox());
			bullet[i].updateModelBound();
			bullet[i].setLocalRotation(new Quaternion(player.getPlayer().getLocalRotation()));
			bullet[i].setRenderState(Utils.createMaterialState(ColorRGBA.blue));
			player.getPlayer().getParent().attachChild(bullet[i]);
			bullet[i].addController(new ShootController(bullet[i],
					ev,
					player.getBulletPosition(i), 
					direction));
			bullet[i].updateRenderState();
			bullet[i].updateGeometricState(0, true);
		}
		player.getPlayer().getParent().updateRenderState();
	}
}